package com.zhipu.resetbalance.ui.home.system;

import android.app.Activity;
import android.content.Intent;
import android.provider.Settings;

import androidx.lifecycle.ViewModel;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.LogUtils;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;
import com.zhipu.resetbalance.mobile.temporaryClass.VersionUpdate;
import com.zhipu.resetbalance.pop.Intranet.IntranetSettingsPopup;
import com.zhipu.resetbalance.ui.home.system.bh.NumberManagementActivity;
import com.zhipu.resetbalance.ui.home.system.device.DeviceActivity;
import com.zhipu.resetbalance.ui.home.system.inspector.InspectorActivity;
import com.zhipu.resetbalance.utils.InitializeUtils;
import com.zhipu.resetbalance.utils.popup.PopupUtils;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class SystemSettingViewModel extends ViewModel {

    /**
     * WIFI设置
     */
    public void wIFISetting(){
        Intent wifiSettingsIntent = new Intent(Settings.ACTION_WIFI_SETTINGS);
        wifiSettingsIntent.putExtra("extra_prefs_show_button_bar", true);
        wifiSettingsIntent.putExtra("extra_prefs_set_next_text", "完成");
        ActivityUtils.startActivity(wifiSettingsIntent);
    }



    /**
     * 检测人员管理
     */
    public void InspectionPersonnelMnagement(){
        /**
         * 检测人员管理
         */
        ActivityUtils.startActivity(InspectorActivity.class);
    }


    /**
     * 内网设置
     */
    public void IntranetSettings(){
        Activity mActivity = ActivityUtils.getTopActivity();
        IntranetSettingsPopup mIntranetSettingsPopup = new IntranetSettingsPopup(mActivity);
        new XPopup
                .Builder(mActivity)
                .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                .asCustom(mIntranetSettingsPopup)
                .show();
    }


    /**
     * 检测更新
     */
    public void DetectionUpdate(){
        /**
         * 显示弹框
         */
        PopupUtils.showBeCommonPopup(ActivityUtils.getTopActivity());
        PopupUtils.SettingBeCommonPopup("请求中...");



        Observable<VersionUpdate> mObservable = InitializeUtils.getAppComponent().getSystemService().version();
        mObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<VersionUpdate>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(VersionUpdate versionUpdate) {
                PopupUtils.dismissAwaitTipsPopup();
                PopupUtils.showAccordingToUpdate(versionUpdate);
            }

            @Override
            public void onError(Throwable e) {
                LogUtils.d("onError:" + e.getMessage());
            }

            @Override
            public void onComplete() {

            }
        });
    }



    /**
     * 设备信息
     */
    public void DeviceInformation(){
        /**
         * 编号管理
         */
        ActivityUtils.startActivity(DeviceActivity.class);
    }


    /**
     * 编号管理
     */
    public void NumberManagement(){
        /**
         * 编号管理
         */
        ActivityUtils.startActivity(NumberManagementActivity.class);
    }


    /**
     * 获取设备数据
     */
    public void ObtainDeviceData(){

    }



    /**
     * 关闭程序
     */
    public void CloseProcedure(){
        ActivityUtils.finishAllActivities();
        AppUtils.exitApp();
    }




    /**
     * 主菜单
     */
    public void mainMenu(){
        /**
         * 主菜单
         */
        ActivityUtils.finishActivity(SystemSettingActivity.class);
    }
}
